package com.tengju.data.infrastructure.repository;

import com.tengju.data.domain.model.exchvesion.DataExchVersionRepository;
import com.tengju.data.domain.model.exchvesion.DataName;
import com.tengju.data.domain.model.exchvesion.DataExchVersion;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.DataExchVersionDO;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.data.custom.DataExchVersionMapper;
import com.tengju.data.infrastructure.repository.convert.DataVersionConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Repository
public class DataExchVersionRepositoryImpl implements DataExchVersionRepository {

    @Resource
    DataExchVersionMapper dataExchVersionMapper;

    @Override
    public DataExchVersion queryVersion(DataName dataName) {
        DataExchVersionDO dataExchVersionDO = dataExchVersionMapper.query(dataName.getCode());
        return DataVersionConvert.toModel(dataExchVersionDO);
    }

    @Override
    public void save(DataExchVersion dataExchVersion) {

        DataExchVersionDO dataExchVersionDO = new DataExchVersionDO();
        dataExchVersionDO.setDataName(dataExchVersion.getDataName());
        dataExchVersionDO.setQueryValue(dataExchVersion.getQueryValue());
        dataExchVersionDO.setVersion(dataExchVersion.getVersion());
        dataExchVersionDO.setStatus(dataExchVersion.getStatus());
        dataExchVersionDO.setCreateTime(dataExchVersion.getCreateTime());
        dataExchVersionDO.setUpdateTime(dataExchVersion.getUpdateTime());
        dataExchVersionMapper.save(dataExchVersionDO);
    }
}
